﻿using SmartPlant.Model.Biz;
using SmartPlant.WinCore;
using System;
using System.Collections.Generic;

namespace SmartPlant.Services
{
    /// <summary>
    /// 支持动态创建表格列基类。
    /// </summary>
    public abstract class DynamicColumnService : BaseService
    {
        /// <summary>
        /// 转换数据列。
        /// </summary>
        /// <param name="viewQueryItems"></param>
        /// <returns></returns>
        protected virtual List<DynamicPropertyInfo> ConvertColumns(List<ViewQueryItemAttr> viewQueryItems)
        {
            var propertyInfos = new List<DynamicPropertyInfo>();
            foreach (var item in viewQueryItems)
            {
                var pi = item.MapTo<DynamicPropertyInfo>();
                pi.IsDropDown = item.WPF_IsDropDown;
                pi.ATTRIBUTE_DATATYPE = item.ATTRIBUTE_DATATYPE;
                pi.PrimaryKey = item.PrimaryKey;
                pi.PropertyName = item.WPF_UniqueName; // name + itemattributionid
                pi.IsReadOnly = item.WPF_readonlymask == "3";
                pi.IsVisible = item.IsDisplayed == 1 ? true : false;
                pi.Order = item.SeqNum;
               
                pi.PropertyType = item.WPF_DATATYPE;
                pi.ItemAttributionId = item.ItemattributionId;
                if (pi.DisplayName.IsNullOrEmpty())
                {
                    pi.DisplayName = item.OrigDisplayName;
                }
                else
                {
                    // pi.DisplayName 已经通过MapTo，从viewQueryItems 中得到
                }
                propertyInfos.Add(pi);
            }
            return propertyInfos;
        }
    }
}
